package come.bjpowernode.javase.threadlocal;

import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

public class Test2 {
    public static void main(String[] args) {
        ThreadLocal<String> local = new ThreadLocal<>();
        Random random = new Random();

        IntStream.range(0,5).forEach(value -> new Thread(()->{
            local.set(value+" " +random.nextInt(10));
            System.out.println("线程local的值分别是"+local.get());
            try{
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start());
    }
}
